
package code.rocky.chapter03;

// 建议37：构造代码块会想你所想
public class Suggest37 {
    public static void main(String[] args) {
        new BaseOne();
        new BaseOne("");
        new BaseOne(0);
        System.out.println("实例对象数量: " + BaseOne.getNumOfObjects());
    }
}

class BaseOne {

    private static int numOfObjects = 0;

    {
        // 构造代码块, 计算产生对象数量
        numOfObjects++;
    }

    public BaseOne() {

    }

    public BaseOne(String str) {

    }

    // 有参构造调用无参构造
    public BaseOne(int i) {

    }

    public static int getNumOfObjects() {
        return numOfObjects;
    }
}